<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户管理</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/plupload/plupload.full.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery-ui/jquery-ui.js"></script>

<script src="${pageContext.request.contextPath}/js/bootstrap/bootstrap.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/table/bootstrap-table.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/table/locale/bootstrap-table-zh-CN.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/table/plugins/tableExport.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/table/plugins/table-export.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/table/plugins/jquery.base64.js" type="text/javascript"></script>

<script src="${pageContext.request.contextPath}/ui/layui/layui.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/layui/lay/modules/laydate.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/ui/layui/lay/modules/layer.js" type="text/javascript"></script>
 <script src="${pageContext.request.contextPath}/ui/layui/lay/modules/form.js" type="text/javascript"></script>
 <link rel="stylesheet" href="${pageContext.request.contextPath}/ui/layui/css/modules/laydate/laydate.css" >
 <link rel="stylesheet" href="${pageContext.request.contextPath}/css/jquery-css/jquery-ui.css">
 <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap-css/bootstrap.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/ui/table/bootstrap-table.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/ui/layui/css/layui.css" >
<link rel="stylesheet" href="${pageContext.request.contextPath}/ui/layui/css/global.css" >
<link rel="stylesheet" href="${pageContext.request.contextPath}/ui/layui/css/modules/layer/default/layer.css" >
 <link rel="stylesheet" href="${pageContext.request.contextPath}/ui/layui/css/modules/code.css" >


 <style>
  .container{
   	width:85%;
   	
  }
  
  .modal-company{
  	width:700px;
  }
  .modal-body{
    max-height:750px
  }
   .modal-body-company{
  	height:600px;
  }
  
   .modal-account{
  	width:400px;
  	z-index:2000;
  	left:65%;
  	
  }
  
  .modal-account.fade.in{
    top:15%;
  }
 
  
   .modal-body-account{
  	height:200px;
  }
  

  
  
  
  </style>

</head>

<body>
<%@include file="/webpage/frame/top.jsp" %>
<div class="container">
	 <div id="progressbar" ></div><div id="finish"  style="font-weight:bold;font-size:20px;margin: 10px auto" > <button id="uploader" style="height:40px;width:150px;margin:  10px auto " >上传备份文件</button>&nbsp;&nbsp;请选择要上传的beb文件</div>
	 	
	 <div class="layui-form-pane" style="margin-top: 15px;">
  			
  			 
      </div>
		
		
     
		<table id="companytable"  data-show-refresh="true"
               data-search="true"
               data-click-to-select="true"
               data-show-export="true"
               data-query-params="queryParams"
			   data-pagination="true"		   
               data-toolbar=".toolbar"
               >
               <!-- data-show-columns="true"  -->
            <thead>
            <tr>
            	<th data-field="state" data-radio="true"></th>
            	<th data-field="id" data-show="true" data-visible="false">id</th>
                <th data-field="companyName" data-sortable="true">客户公司名称</th>
               
                <!-- <th data-field="registerTime">注册时间</th> -->
                <th data-field="username" data-sortable="true">负责客服</th>
                <th data-field="industry" data-sortable="true">所属行业</th>
               
                <th data-field="action"
                    data-align="center"
                    data-formatter="actionFormatter"
                    data-events="actionEvents">操作</th>
                    
            </tr>
            </thead>
			
		</table>
		</div>

	
	
<script>

    var API_URL = '${pageContext.request.contextPath}/companyController.do?getCompanysAndIsGood';
	
  
    
    //获取加载公司列表
			var $table = $('#companytable').bootstrapTable(
    		{
    			url: API_URL,
    			pageSize:25,
    			pageList : [15, 25, 100, 500]
    		}
    		
    
    ),
      
        
        $alert = $('.alert').hide();
	
		
    
   
	
    $(function () {
    	
    	
    	
    	
    	//拼接json数据
    	
    	
    	//var  accountPlatformName = $("#typeTag").find("option:selected").text();
    	//$("#accountPlatformName").val(
    	//		accountPlatformName
    	//);
    	

    $(function () {
    	//获取选中值
    	
    	 TableExport.init();
    	//导出按钮
    	$('#export').click(function () {
    		
    	  	$table.tableExport({
    	      type: 'excel',
    	      escape: false
    	    });
    	  });
        // create event
      

       
            
            
            
        });
    });
    
    function queryAccountParams(params) {  //配置参数  
        
    	
    	var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的  
          companyId:$modal.data("id")
           
        };  
        return temp;  
      }  

    function queryParams(params) {
        return {};
    }

    function actionFormatter(value,row,index) {
    	buttonArray =  new Array();
    	
    		//&companyName="+"\""+name+"\""+"\""
    		//var id =row.id;
    		
    		//var str = "<a class=\"download-backup btn btn-default\" href=\"${pageContext.request.contextPath}/companyController.do?downloadBackup&id="+id+"\""+" >下载备份</a>"  
    		
 
    		if (row.hasPath ) {
				buttonArray[0] = '<a class="detail btn btn btn-default" href="javascript:" title="修改公司资料">详情</a>';
				
			}
    		
    	
        return buttonArray.join(' ');
    }
    
    

    // update and delete events
    window.actionEvents = {
    		
    		
    		'click .detail' : function(e, value, row){
	    		
	    		
		    	$(location).attr('href','${pageContext.request.contextPath}/companyController.do?getSemBackupDescription&id='+row.id);
		    		
		    
		    
		    },
    
    }

    
   
</script>
<!-- 上传组件初始化代码 -->

 <script type="text/javascript">
 //上传公司筛选
 
 	    var companyid="";
 		var industryId= '';
 		var accountId = '';
 		var interval_import = '';
 		var upload_click = false;
        var uploader;
        var downloadbackup;
        
       
        upload();
        uploader.init();
        
      
      
      //上传文件
      function upload(){
    	  uploader = new plupload.Uploader({
    		  runtimes : 'html5,flash,silverlight,html4',//设置运行环境，会按设置的顺序，可以选择的值有html5,gears,flash,silverlight,browserplus,html
              flash_swf_url : './js/plupload/Moxie.swf',
              silverlight_xap_url : './js/plupload/Moxie.xap',
              url : '${pageContext.request.contextPath}/uploadBebFile.do?companyId='+companyid,//上传文件路径
              max_file_size : '50mb',//100b, 10kb, 10mb, 1gb
              chunk_size : '50mb',//分块大小，小于这个大小的不分块
              unique_names : true,//生成唯一文件名
              browse_button : 'uploader', 
              filters: [{title: "Custom Files",extensions: "beb"}],//图片限制
             
              init : {
            	 
              	FileFiltered:function(up,file){
              		//$("#finish").html("请选择正确的文件类型")
              	},
                  FilesAdded: function(up, files) {
                	 
                      uploader.start();
                     // $("#finish").html("开始上传")
                     
                  },
                  FileUploaded : function(up, file, info) {//文件上传完毕触发
                  	
                  },
                  UploadComplete : function( uploader,files ) {
                		alert("上传成功！");
						$table.bootstrapTable('refresh');
                     		
                  },
                  
                     
                  
                  Error: function(up, args) {
                      // Called when error occurs
                    
                     
                  }
              }
          });
    	  
    	 
    	  
    
      }
           
      
      
      
      
      function isContains(str, substr) {
    	    return str.indexOf(substr) >= 0;
    	}
      
      function getAccount(){
    	  
    	  //console.log('getAccount');
    	  var obj = eval($table.bootstrapTable('getSelections'));
    	 console.log(obj);
    	  companyId=obj[0].id;
    	  industryId = obj[0].industryId;
    	 // console.log(companyId)
    	  accountId= '0';
    	  var GET_ACCOUNT_URL = '${pageContext.request.contextPath}/companyController.do?checkAccount'
    	  $.ajax({  
    	        url: GET_ACCOUNT_URL  
    	        , type: "POST"
    	        , async:true
    	        , data: {  
    	        	companyId:companyId
    	        }, 
    	        dataType :"json" ,
    	        beforeSend: function(request){  
    	        }, success: function(data, status){
    	        	
    	        	
    	        	accountId= data;
    	        	
    	        	if(accountId!='0'){
    	        		console.log($(".moxie-shim-html5").find('input[type=file]'));
    	        	
        	        	uploader.settings.url = '${pageContext.request.contextPath}/uploadBebFile.do?accountId='+accountId+'&industryId='+industryId+'&companyId='+companyId
    	        		
    	        	}else{
    	        		alert('此公司面没有添加百度账号');
    	        		return false;
    	        	}
    	        		return true;
    	        		
    	        }, error: function(request, error, status){  
    	            // todo: 错误处理  
    	        }, complete: function(request, error, status){  
    	        }  
    	    });  
    	  
    	 	return false;
      }
      
      $(
    	
    	function(){
    		$("#uploader").mouseover(
    				
    			function(){
    				
    				if($(".bs-checkbox input:radio[name='btSelectItem']:checked").val()==undefined){
    					alert("请选择一间公司");
    				    //uploader.destroy();	
    					return  false;
    				}else{
    					
    					getAccount();
    			 	}
    			}
    		);
    		 
    	}
    	
    	
    	
    	
      );
      function listenUploadButton(){
  		$("#uploader").mouseover(
  				
      			function(){
      				//console.log('aaa');
      				if($(".bs-checkbox input:radio[name='btSelectItem']:checked").val()==undefined){
      					alert("请选择一间公司");
      				    //uploader.destroy();	
      					return  false;
      				}else{
      					
      					getAccount();
      			 	}
      			}
      		);
  	}

      
</script>    


  

<%@include file="/webpage/frame/bottom.jsp" %>
</body>
</html>